define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order.order/index' + location.search,
                    add_url: 'order.order/add',
                    // edit_url: 'order.order/edit',
                    del_url: 'order.order/del',
                    multi_url: 'order.order/multi',
                    import_url: 'order.order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'orderid', title: __('Orderid'), operate: 'LIKE' },
                        { field: 'goods_name', title: __('Goods_name'), operate: 'LIKE' },
                        { field: 'goods_image', title: __('Goods_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image },
                        // { field: 'goods_description', title: __('Goods_description'), operate: 'LIKE' },
                        { field: 'goods_price', title: __('Goods_price'), operate: false },
                        { field: 'order_type', title: __('Order_type'), searchList: { "1": __('Order_type 1'), "2": __('Order_type 2') }, formatter: Table.api.formatter.normal },
                        { field: 'senddate', title: __('Senddate'), operate: 'RANGE', addclass: 'datetimerange', datetimeFormat: "YYYY-MM-DD HH:mm", autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'takedate', title: __('Takedate'), operate: 'RANGE', addclass: 'datetimerange', datetimeFormat: "YYYY-MM-DD HH:mm", autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'num', title: __('Num') },
                        { field: 'total_fee', title: __('Total_fee'), operate: false },
                        { field: 'total_points', title: __('Total_points'), operate: false },
                        { field: 'pay_type', title: __('Pay_type'), searchList: { "1": __('Pay_type 1'), "2": __('Pay_type 2'), "4": __('Pay_type 4'), "5": __('Pay_type 5') }, formatter: Table.api.formatter.normal },
                        { field: 'order_status', title: __('Order_status'), searchList: { "0": __('Order_status 0'), "10": __('Order_status 10'), "15": __('Order_status 15'), "20": __('Order_status 20'), "30": __('Order_status 30'), "40": __('Order_status 40'), "50": __('Order_status 50'), "60": __('Order_status 60') }, formatter: Table.api.formatter.status },
                        { field: 'take_images', title: __('Take_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images },
                        { field: 'taketime', title: __('Taketime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'cleantime', title: __('Cleantime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'clean_images', title: __('Clean_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images },
                        { field: 'take.nickname', title: __('Take_id') },
                        { field: 'send.nickname', title: __('Send_id') },
                        { field: 'take_code', title: __('Take_code'), operate: 'LIKE' },
                        { field: 'mark', title: __('Mark'), operate: 'LIKE' },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'paytime', title: __('Paytime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'sendtime', title: __('Sendtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'address.contact', title: __('Address.contact'), operate: 'LIKE' },
                        { field: 'address.telephone', title: __('Address.telephone'), operate: 'LIKE' },
                        // {field: 'address.address', title: __('Address'), operate: 'LIKE'},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'view',
                                    title: '查看',
                                    text: '查看',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'order/order/view',//接口地址 控制器名/方法名
                                },
                                {
                                    name: 'distribution',
                                    title: '配送',
                                    text: '配送',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'order/order/distribution',//接口地址 控制器名/方法名
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if ((row.order_type == '1' && row.order_status == '10') || (row.order_status == '20' && row.address !=null)) {
                                            return true;//显示
                                        } else {
                                            return false;//隐藏
                                        }
                                    },
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        distribution: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
